<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" version="-//W3C//DTD XHTML 1.1//EN" dir="ltr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="js/json2.js"></script>
    <script language="javascript" type="text/javascript" src="js/jsonssproxy.js"></script>
    <link href="css/samples.css" rel="stylesheet" type="text/css">
    <title>HelloService demo</title>
</head>
<body><div id="page-content">
 
    <h1>HelloService demo</h1>

    <p class="bar">
        <input id="callSayHello" type="button" value="Say Hello" onclick="callSayHello();">
    </p>
    <p>
        HelloService (<a href="hello.php?service-source">view source</a>) exposes only one method:
        <ul>
            <li>SayHello() - as one may expect, returns string "Hello, world!"</li>
        </ul>
    </p>

    <p>
        Exchage log:
    </p>
    <pre id="log" class="console"></pre>

    <div class="cr_footer">Released under GPLv2, (C) 2012 Serge V. Izmaylov</div>

    <script type="text/javascript">
        //<![CDATA[
        var prx;

        function callSayHello() {
            try {
                $("#log").append("Calling HelloService.SayHello():\r\n");
                var res = prx.HelloService.SayHello();
                $("#log").append("HTTP POST to " + prx.HelloService.serviceUrl + "/" + prx.HelloService._members["SayHello"].u + "\r\n");
                $("#log").append(prx.HelloService.lastRequestHeaders + "\r\n");
                $("#log").append(prx.HelloService.lastRequest + "\r\n\r\n");
                $("#log").append("RESPONSE" + "\r\n");
                $("#log").append(prx.HelloService.lastResponseHeaders + "\r\n");
                $("#log").append(prx.HelloService.lastResponse + "\r\n");
                alert("HelloService.SayHello() said: " + res);
            } catch (x) {
                if (x instanceof JSONSSError) {
                    $("#log").append("callSayHello fault: " + x.message + "\r\nadditional data: " + JSON.stringify(x.data) + "\r\n");
                    alert("callSayHello fault: " + x.message + "\r\n" + JSON.stringify(x.data));
                } else {
                    $("#log").append("callSayHello exception: " + x.toString() + "\r\n");
                    alert("callSayHello exception: " + x.toString());
                }
            }
        }

        $(document).ready(function () {
            try {
                var serviceurl = location.href;
                serviceurl = serviceurl.replace(/.htm$/, ".php");
                $("#log").append("Loading service interface:\r\n");
                $("#log").append("HTTP GET to " + serviceurl + "\r\n");
                prx = JSONSSProxy.fromUrl(serviceurl);
                $("#log").append("Got proxy object" + "\r\n");
                $("#log").append("HelloService base url is " + prx.HelloService.serviceUrl + "\r\n\r\n");
            } catch (x) {
                if (x instanceof JSONSSError) {
                    $("#log").append("JSONSSProxy.fromUrl fault: " + x.message + "\r\n" + JSON.stringify(x.data) + "\r\n");
                    alert("JSONSSProxy.fromUrl fault: " + x.message + "\r\n" + JSON.stringify(x.data));
                } else {
                    $("#log").append("JSONSSProxy.fromUrl exception: " + x.toString() + "\r\n");
                    alert("JSONSSProxy.fromUrl exception: " + x.toString());
                }
            }
        });
        //]]>
    </script>
</div></body>
</html>
